package com.lifo.utils.queue.hfgooddescriptionqueue;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.concurrent.*;

/**
 * Created by Administrator on 2018/5/17 0017.
 */
@Component
public class HfGoodDescriptionPoolExecutor  {

   @Autowired
    private ProduceHfGoodDescription produceHfGoodDescription;

    @Autowired
    private ConsumerHfGoodDescription consumerHfGoodDescription;

    @Autowired
    private ThreadPoolExecutor taskThreadPool;

    public class HfGoodDescriptionTask implements Runnable{
        @Override
        public void run() {
            try {
                consumerHfGoodDescription.cleanHfGoodDescription();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }


    @PostConstruct
    void justGo(){
          Executors.newSingleThreadExecutor().execute(() -> {

            taskThreadPool.execute(() -> {
                produceHfGoodDescription.addHfGoodDescriptions();
            });

           });

    }


    public void xianchengchi(){
      /*  Executors.newSingleThreadExecutor().execute(() -> {*/
            while(true) {
                taskThreadPool.execute(() -> {
                   new HfGoodDescriptionTask().run();
                });
            }
      /*  });*/
    }

}
